package io.char_stream;

import java.io.*;


/*
用指定编码表读写字符：转换流！！！
 */
public class Demo07_TransIO {
    public static void main(String[] args) throws IOException {
        //extracted();
        //用BufferedReader提升效率
        BufferedReader br = new BufferedReader(new InputStreamReader(
                new FileInputStream("wzx.txt"),"utf-8"));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream("gbk.txt"),"gbk"));

        int c;
        while((c = br.read()) != -1) {
            bw.write(c);
        }

        br.close();
        bw.close();
    }

    private static void extracted() throws IOException {
        //用指定码表读字符
        InputStreamReader isr = new InputStreamReader(new FileInputStream("wzx.txt"),"utf-8");
        //用指定码表写字符
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("gbk.txt"),"gbk");

        int c;

        while((c = isr.read()) != -1) {
            osw.write(c);
        }

        isr.close();
        osw.close();
    }
}
